<?php

namespace app\common\model\activity;

use app\common\utils\Utils;
use think\Model;
use traits\model\SoftDelete;

class News extends Model
{

    use SoftDelete;

    

    // 表名
    protected $name = 'activity_news';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'is_show_text',
        'createtime_text',
        'image_text'
    ];

    public function getImageTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['image']) ? $data['image'] : '');

        return cdnurl($value, true);
    }

    public function getCreatetimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['createtime']) ? $data['createtime'] : '');

        return Utils::time_format($value);
    }
    public function getIsShowList()
    {
        return ['0' => __('Is_show 0'), '1' => __('Is_show 1')];
    }


    public function getIsShowTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_show']) ? $data['is_show'] : '');
        $list = $this->getIsShowList();
        return isset($list[$value]) ? $list[$value] : '';
    }




    public function activitycategory()
    {
        return $this->belongsTo('app\common\model\activity\Category', 'category_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
